import time
import pyautogui
import sys

import win32com
import mgrid
import win32gui

def GetMainWnd():
    hwnd = win32gui.FindWindow('Chrome_WidgetWin_0', '砖了个砖')    
    if hwnd == None:
        return False
    windows = pyautogui.getWindowsWithTitle("砖了个砖")
    mainwin = None
    for w in windows:
        if w._hWnd == hwnd:
            mainwin = w
            break
    return mainwin

if __name__ == "__main__":
    pyautogui.PAUSE = 2.5
    pyautogui.FAILSAFE = True
    print("start")
    mainwin = GetMainWnd()
    if mainwin == None:
        print("没有找到")
        sys.exit(0)
    mainwin.move(0,0)
    mainwin.activate()
    if mainwin.box.left < -32000:
        print("窗口小于-30000")
        sys.exit(0)
    pos = (mainwin.box.left + 14, mainwin.box.top + 152)
    grid = mgrid.MGrid("bb",pos,(42,42.5),(30,30),(10,14),0.8)
    # grid.Capture()
    # grid.Collect()
    grid.MakeData()
    print("end")
